let { $, table, layer, form ,upload} = layui;
export default class Add {
    constructor() {
        this.render();
        this.handle();
    }
    render() {
        let template = `
            <table id="allTable" lay-filter="allTable"></table>
        `;
        $("#addSoonsTemplate").html(template);
    }
    handle() {
                layer.open({
                  type: 1 //Page层类型
                  , skin: 'layui-layer-molv'
                  , area: ['1000px', '400px']
                  , title: ['所有电影', 'font-size:18px']
                  , btn: ['添加', '取消'], 
                  success: function () {
                    table.render({
                        id:"all",
                        elem: '#allTable',
                        url: '/films/',
                        method: "get",
                        page: true,
                        limit: 5,
                        limits: [5, 10, 15],
                        request: {
                          pageName: 'current',
                          limitName: 'pageSize'
                        },
                        parseData: function (res) {
                          return {
                            code: 0,
                            count: res.data.total,
                            data: res.data.rows
                          }
                        },
                        // toolbar: "#tools",
                        cols: [[ //表头
                          {field:'checkbox', type:'checkbox',checked:'true', width:'5%'},
                          { field: 'name', title: '电影名' },
                          { field: 'ename', title: '电影英文名' },
                          { field: 'type', title: '电影类型' },
                          { field: 'area', title: '上映区域' },
                          { field: 'score', title: '评分' },
                          { field: 'actor', title: '演员', templet(d) {
                            console.log(d);
                            let str = "";
                            for (let i of d.actor) {
                              str += d.actor ? i.name + ',' : "";
                            }
                            return str;
                          }},
                          { field: 'year', title: '年代' },
                          { field: 'time', title: '时长' },
                          { field: 'upDate', title: '上映时间' },
                          { field: 'count', title: '票房' },
                          { field: 'images', title: '图片' }
                        ]]
                      });
                  },
                  yes: function (index) {
                      let checkStatus=table.checkStatus('all');
                      console.log(checkStatus.data[0]._id);
                      let arr=[];
                      for (let i = 0; i < checkStatus.data.length; i++) {
                        arr.push(checkStatus.data[i]._id);
                      }
                      console.log("arr",arr);
                      $.ajax({
                        type: "post",
                        url: "/hotPlay",
                        data:{films:JSON.stringify(arr)},
                        success(res) {
                            console.log('res',res);
                            table.reload("soonsTable", {
                                where: {}
                              })
                              layer.close(index);
                        }
                      });
                  },
                  content: $("#addSoonsTemplate").html()
                });
                
    }
}
